package com.cp.admin.modular.user.controller;

import com.cp.admin.modular.user.model.UserFriend;
import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.user.service.IUserFriendService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2020-08-26 09:50:01
 */
@Controller
@RequestMapping("/userFriend")
public class UserFriendController extends BaseController {

    private String PREFIX = "/user/userFriend/";

    @Autowired
    private IUserFriendService userFriendService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "userFriend.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/userFriend_add")
    public String userFriendAdd() {
        return PREFIX + "userFriend_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/userFriend_update/{userFriendId}")
    public String userFriendUpdate(@PathVariable Long userFriendId, Model model) {
        UserFriend userFriend = userFriendService.selectById(userFriendId);
        model.addAttribute("item",userFriend);
        LogObjectHolder.me().set(userFriend);
        return PREFIX + "userFriend_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return userFriendService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UserFriend userFriend) {
        userFriendService.insert(userFriend);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long userFriendId) {
        userFriendService.deleteById(userFriendId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UserFriend userFriend) {
        userFriendService.updateById(userFriend);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{userFriendId}")
    @ResponseBody
    public Object detail(@PathVariable("userFriendId") Long userFriendId) {
        return userFriendService.selectById(userFriendId);
    }
}
